// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/base/api/ScheduleSettingApi'

import InfoClass from '@api/base/model/ScheduleSettingReq'
import AddClass from '@api/base/model/ScheduleSettingOperateReq'
import BaseClass from '@api/base/model/ScheduleSettingDto'

const EditClass = AddClass

const CLIENT = CORE.grpcCLIENT(Client)
const BASE = [BaseClass, 'content']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 信息 —————————————————————————————— //

  async getInfo(infoParam, TIP = '查询信息') {
    const DTO = CORE.grpcDTO(InfoClass, infoParam)
    const resp = await CORE.grpc(TIP, CLIENT, 'queryScheduleSettingDetail', DTO)
    return resp.content || {}
  },
  transInfo(obj) {
    obj.allowLate = obj.lateMaxTime ? 1 : 2
    obj.allowEarly = obj.earlyMaxTime ? 1 : 2
    return obj
  },

  // —————————————————————————————— 增 —————————————————————————————— //

  transAdd(one, { state: { info } }) {
    return info
  },
  async add(one, TIP = '新增') {
    const DTO = CORE.grpcDTO(EditClass, one, BASE)
    await CORE.grpc(TIP, CLIENT, 'insertScheduleSetting', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  transEdit(one, { state: { info } }) {
    return info
  },
  async edit(one, TIP = '修改') {
    const DTO = CORE.grpcDTO(EditClass, one, BASE)
    await CORE.grpc(TIP, CLIENT, 'updateScheduleSetting', DTO)
    return CORE.grpcOK(TIP)
  },
}
